/*
    Android UIML

	Copyright (C) 2010  Bram Goffings (bramgoffings@gmail.com)

	This program is free software; you can redistribute it and/or
	modify it under the terms of the GNU Lesser General Public License
	as published by the Free Software Foundation; either version 2.1
	of	the License, or (at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU Lesser General Public License for more details.

	You should have received a copy of the GNU Lesser General Public License
	along with this program; if not, write to the Free Software
	Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

package uiml.android.elements.peers;

import java.util.ArrayList;

import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;

import uiml.android.elements.UimlElementWithAttributes;
import uiml.android.template.Template;

public class DClass extends UimlElementWithAttributes{
	
	// TODO comment
	private ArrayList<DMethod> dmethods = new ArrayList<DMethod>();
	private ArrayList<DProperty> dproperties = new ArrayList<DProperty>();
	private ArrayList<Event> events = new ArrayList<Event>();

	
	private String mapsTo = null;
	private String mapsType = null;
	private String usedInTag = null;

	// TODO comment
	public final static String IAM = "d-class";
	
	public final String DMETHOD = "d-method";
	public final String DPROPERTY = "d-property";
	public final String EVENT = "event";
	public final String LISTENER = "listener";
	
	public final String MAPSTO = "maps-to";
	public final String MAPSTYPE = "maps-type";
	public final String USEDINTAG = "used-in-tag";
	
	
	/**
	 * 
	 * @param node
	 */
	public DClass(Element node) {
		super(node);
		process();
	}

	/**
	 * 
	 */
	@Override
	protected Object clone() {
		// TODO Auto-generated method stub
		return null;
	}
	
	/**
	 * 
	 */
	@Override
	public void processElement(Element elem) {
		
		if(elem.getTagName().equals(DMETHOD))
			dmethods.add(new DMethod(elem));
		else if(elem.getTagName().equals(DPROPERTY))
			dproperties.add(new DProperty(elem));
		else if(elem.getTagName().equals(EVENT))
			events.add(new Event(elem));
	}
	
	/**
	 * 
	 */
	@Override
	public void processAttributes() {
		
		super.processAttributes();
		
		NamedNodeMap attributes = node.getAttributes();
		
		if(attributes != null) {
			if(attributes.getNamedItem(MAPSTO) != null)
				setMapsTo(attributes.getNamedItem(MAPSTO).getNodeValue());
			if(attributes.getNamedItem(MAPSTYPE) != null)
				setMapsType(attributes.getNamedItem(MAPSTYPE).getNodeValue());
			if(attributes.getNamedItem(USEDINTAG) != null)
				setUsedInTag(attributes.getNamedItem(USEDINTAG).getNodeValue());
		}
	}
	
	/**
	 * 
	 * @param t
	 */
	public void applyCascadeTemplate(Template t) {
		
		DClass cascadeInterface = (DClass)t.getTop();
		
		dmethods.addAll(cascadeInterface.getDMethods());
		dproperties.addAll(cascadeInterface.getDProperties());
		events.addAll(cascadeInterface.getEvents());
	}

	/**
	 * @param mapsTo the mapsTo to set
	 */
	public void setMapsTo(String mapsTo) {
		this.mapsTo = mapsTo;
	}

	/**
	 * @return the mapsTo
	 */
	public String getMapsTo() {
		return mapsTo;
	}

	/**
	 * @param mapsType the mapsType to set
	 */
	public void setMapsType(String mapsType) {
		this.mapsType = mapsType;
	}

	/**
	 * @return the mapsType
	 */
	public String getMapsType() {
		return mapsType;
	}

	/**
	 * @param usedInTag the usedInTag to set
	 */
	public void setUsedInTag(String usedInTag) {
		this.usedInTag = usedInTag;
	}

	/**
	 * @return the usedInTag
	 */
	public String getUsedInTag() {
		return usedInTag;
	}	
	
	/**
	 * 
	 * @return
	 */
	public ArrayList<DMethod> getDMethods() {
		return dmethods;
	}

	/**
	 * 
	 * @param dmethods
	 */
	public void setDMethods(ArrayList<DMethod> dmethods) {
		this.dmethods = dmethods;
	}

	/**
	 * 
	 * @return
	 */
	public ArrayList<DProperty> getDProperties() {
		return dproperties;
	}

	/**
	 * 
	 * @param dproperties
	 */
	public void setDProperties(ArrayList<DProperty> dproperties) {
		this.dproperties = dproperties;
	}

	/**
	 * 
	 * @return
	 */
	public ArrayList<Event> getEvents() {
		return events;
	}

	/**
	 * 
	 * @param events
	 */
	public void setEvents(ArrayList<Event> events) {
		this.events = events;
	}

}
